<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="/layer/layer.js"></script>
</head>
<body>
<div id="updateResource" class="container">
    <form class="form-horizontal" action="" method="post">
        <input name="id" value="${resource.id}" hidden>
        <div class="form-group">
            <label for="name" class="col-sm-2 control-label">角色名</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" id="name" placeholder="角色名" v-model="resourceInfo.name">
            </div>
        </div>
        <div class="form-group">
            <label for="url" class="col-sm-2 control-label">地址</label>
            <div class="col-sm-10">
                <input type="text" class="form-control" id="url" placeholder="地址" v-model="resourceInfo.url">
            </div>
        </div>
        <div class="form-group">
            <label for="url" class="col-sm-2 control-label">地址</label>
            <div class="col-sm-10">
                <select name="pid" class="form-control" v-model="resourceInfo.pid">
                    <option value="0">根节点</option>

                    <option v-for="d in resourceList" :value="d.id">{{d.name}}</option>

                </select>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <button type="button" class="btn btn-default" @click="updateResource">保存</button>
            </div>
        </div>
    </form>
</div>
<script>
    new Vue({
        el: "#updateResource",
        data: {
            resourceInfo: {},
            resourceList: [],
            id: get_parameter("id")
        },
        created() {
            this.resourceList1();
            this.findById();
        },
        methods: {
            updateResource() {
                var vm = this;
                $.post("/resource/update", vm.resourceInfo, function (response) {
                    if (response.code == 200) {
                        parent.layer.close(parent.layer.getFrameIndex(window.name));
                    }
                })
            },
            resourceList1() {
                var vm = this;
                $.post("/resource/resourceList1",{id:vm.id}, function (response) {
                    vm.resourceList = response.data
                })
            },
            findById() {
                var vm = this;
                $.post("/resource/findById",{id:vm.id}, function (response) {
                    if (response.code == 200) {
                        vm.resourceInfo=response.data
                    }
                })
            }
        }

    })
    //获取路径中的值
    function get_parameter(name) {
        var lot = location.search;
        var reg = new RegExp(".*" + name + "\\s*=([^=&#]*)(?=&|#|).*", "g");
        return decodeURIComponent(lot.replace(reg, "$1"));
    }
</script>
</body>
</html>